package com.mew.common.entity.mail;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import java.util.Date;

import com.zebra.common.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import lombok.*;
import lombok.experimental.Accessors;

/**
 * <p>
 * 邮件
 * </p>
 *
 * @author Dylin
 * @since 2021-04-01
 */
@Data
@TableName("m_mail")
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Mail implements Serializable {

    private static final long serialVersionUID=1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 类型
     */
    private Integer type;

    /**
     * 批次
     */
    private Integer batch;

    /**
     * 标题
     */
    private String title;

    /**
     * 正文
     */
    private String content;

    /**
     * 发送人
     */
    private Long sendUser;

    /**
     * 接收人
     */
    private Long receiveUser;

    /**
     * 发送时间
     */
    private Date sendTime;
    /**
     * 领取时间
     */
    private Date receiveTime;

    /**
     * 状态
     */
    private Integer status;

    public void write(ByteBuf b) {
        //TODO 只发送 需要的用户信息
        ByteBufUtils.writeInt(b,id);
        ByteBufUtils.writeLong(b,sendUser == null? -1 : sendUser);
        ByteBufUtils.writeInt(b,type);
/*      ByteBufUtils.writeString(b,title);
        ByteBufUtils.writeString(b,content);

        ByteBufUtils.writeLong(b,receiveUser);
        ByteBufUtils.writeString(b, DateUtil.formatDate(receiveTime));*/
        ByteBufUtils.writeString(b, DateUtil.formatDateTime(sendTime));
        ByteBufUtils.writeInt(b,status);
    }
}
